package com.leet.string;

public class CountBinarySubstrings {
    public int countBinarySubstrings(String s) {
        int i,k;
        int cnt = 0;
        int ans = 0;
        boolean flag = false;
        for(i = 0 ; i < s.length(); i++){
            cnt=0;
            char head = s.charAt(i);
            for(k = i ; k < s.length();k++){
                if(s.charAt(k) == head && !flag){
                    cnt++;
                }else{
                    flag = true;
                    if(s.charAt(k) == head) {flag = false;break;}
                    cnt--;
                    if(cnt == 0){
                        ans++;
                        flag = false;
                        break;
                    }

                }
            }
        }
        System.out.println(ans);
        return ans;
    }

    public static void main(String[] args) {
        CountBinarySubstrings countBinarySubstrings = new CountBinarySubstrings();
        countBinarySubstrings.countBinarySubstrings("00110");
    }
}
